//
//  GrowlManager.m
//
//  Created by Mechalogical on 27/01/2010.
//  Copyright 2010 Mechalogical Labs.
//
//  This file is part of BattleGrowl.
//  
//  BattleGrowl is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  BattleGrowl is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with BattleGrowl.  If not, see <http://www.gnu.org/licenses/>.
//  

#import "GrowlManager.h"


@implementation GrowlManager

-(id)init
{
	if ([super init] == nil) return nil;
	// register with growl
	[GrowlApplicationBridge setGrowlDelegate:self];	
	
	//Used to detect where our files are
	NSBundle *bundle = [NSBundle mainBundle];
	
	growlIcon = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"BattleGrowlStatusIcon" ofType:@"png"]] ;
	growlIconData = [growlIcon TIFFRepresentation] ;
	
	return self;
}

- (void) postGrowl:(PSEntry*)entry forCharacter:(WowCharacter*)character
{
	NSMutableString *title = [NSMutableString stringWithString:[character name]];
	[title appendString: @" on "];
	[title appendString: [character realm]];
	[title appendString: @"-"];
	[title appendString: [character region]];
	
	NSMutableString *description = [NSMutableString stringWithString:[entry title]];
	
	// Creating growl notification
	[GrowlApplicationBridge
	 notifyWithTitle:title
	 description:description
	 notificationName:@"Achievement"
	 iconData: growlIconData
	 priority:1
	 isSticky:[[NSUserDefaults standardUserDefaults] boolForKey:@"StickyNotifications"]
	 clickContext:entry.identifier];	
}

// GrowlApplicationBridge Callbacks

- (NSDictionary *)registrationDictionaryForGrowl{
	
	NSArray *notifications = [NSArray arrayWithObject: @"Achievement"];
	NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
						  notifications, GROWL_NOTIFICATIONS_ALL,
						  notifications, GROWL_NOTIFICATIONS_DEFAULT, nil];
	
	return dict;
}

- (NSString *) applicationNameForGrowl
{
	return @"Battle Growl";
}

- (void) growlNotificationWasClicked:(id)clickContext
{
	NSLog(@"Growl Notifcation Clicked");	//[self activateIgnoringOtherApps:YES];
	NSLog(clickContext);
}

- (void) dealloc 
{	
	[growlIconData release];
	[growlIcon release];
	[super dealloc];	
}


@end
